package com.ww.util.guava;


import com.google.common.collect.Sets;

import java.util.HashSet;

import static com.google.common.collect.Sets.newHashSet;

public class SetDemo1 {

    public static void main(String[] args) {
        HashSet<Integer> setA = newHashSet(1, 2, 3, 4, 5);
        HashSet<Integer> setB = newHashSet(4, 5, 6, 7, 8);

        /**
         * union
         */
        Sets.SetView<Integer> union = Sets.union(setA, setB);
        System.out.print("并集：");
        for (Integer i : union) {
            System.out.print(i);
            System.out.print(" ");
        }
        System.out.println();

        /**
         * 差集
         */
        Sets.SetView<Integer> diff = Sets.difference(setA, setB);
        System.out.print("差集：");
        for (Integer i : diff) {
            System.out.print(i);
            System.out.print(" ");
        }
        System.out.println();

        /**
         * 交集
         */
        Sets.SetView<Integer> inter = Sets.intersection(setA, setB);
        System.out.print("交集：");
        for (Integer i : inter) {
            System.out.print(i);
            System.out.print(" ");
        }
    }
}
